# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/12 16:14
# @Author   : yangshuaishuai
# @Site     : http://www.hzdledu.cn/
# @File     : a1s3_基于坐标操作.py
# @Software : PyCharm

import unittest
from appium import webdriver
import time

class Test(unittest.TestCase):
    def setUp(self) -> None:
        # 手机设置
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 系统名称
        desired_caps['platformVersion'] = '7.1.2'  # 系统的版本号
        desired_caps['deviceName'] = 'Android Emulator'  # 设备名称，这里是虚拟机，这个没有严格的规定
        desired_caps['appPackage'] = 'com.netease.cloudmusic'  # APP包名
        desired_caps['appActivity'] = 'com.netease.cloudmusic.activity.LoadingActivity'  # APP入口的activity
        desired_caps['noReset'] = True  # 不重置app的缓存文件
        desired_caps['unicodeKeyboard'] = True  # 设置键盘支持中文输入
        desired_caps['resetKeyboard'] = True  # 重置键盘

        # 连接appium server，告诉appium，代码要操作哪个设备上的哪个APP
        # 启动手机上App
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

    def test(self):
        time.sleep(5)
        #点击
        self.driver.find_element_by_accessibility_id('搜索').click()#点击搜索图标
        time.sleep(1)
        #清空输入框
        self.driver.find_element_by_id('com.netease.cloudmusic:id/search_src_text').click()
        time.sleep(1)
        #输入
        self.driver.find_element_by_id('com.netease.cloudmusic:id/search_src_text').send_keys('漠河舞厅')
        time.sleep(1)
        #基于坐标操作
        self.driver.tap([(142,229)])
        time.sleep(1)

        #滑动
        self.driver.swipe(270,480,270,180)
        time.sleep(1)

        time.sleep(5)

    def tearDown(self) -> None:
        self.driver.quit()